package com.tshopping.controller;

import com.tshopping.bean.DataModel;
import com.tshopping.service.CommentService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

/**
 * @name: CommentController
 * @description: 商品评论页面控制器
 * @author: Jackeys
 * @date: 2021-01-31 23:13
 */
@RestController
@RequestMapping("/CommentController")
@CrossOrigin
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping(value = "/addComment")
    /**
     * @description 处理用户添加商品评论
     * @Param: dataModel
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-31 23:17
     */
    public ResponseData addComment(@RequestBody DataModel dataModel) throws ParseException {
        return commentService.addComment(dataModel);
    }

    @PostMapping(value = "/getGoodsComments")
    /**
     * @description 返回商品评论
     * @Param: dataModel
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-31 23:17
     */
    public ResponseData getGoodsComments(int goods,int currentPage){
        return commentService.selectComment(goods,currentPage);
    }

    @PostMapping(value = "/uploadCommentPicture")
    /**
     * @description 上传评论图片
     * @Param: request
     * @Param: email
     * @Param: file
     * @return ResponseData
     * @author Jackeys
     * @date 2021-02-01 00:04
     */
    public ResponseData uploadCommentPicture(HttpServletRequest request, String email, @RequestParam(value = "file", required = false) MultipartFile file){
        return commentService.uploadCommentPicture(request,email,file);
    }
}
